home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
'92_HACK
/
IR_MAN_
/
ATOB_C.OLD
next >
Wrap
Text File
|
1992-06-06
|
1KB
|
78 lines
/* Analog to Binary converter routine.
By: Mike Neil 6/6/92
*/
#include "atob.h"
long
AnalizeData(unsigned char *TheData, long dataSize) {
long ammount;
register long cnt;
register short delt;
register short state;
register short curChar;
short bitCnt;
long outVal;
long counter, duration;
char bits[20];
state = 0;
bits[12] = 0;
bitCnt = 0;
outVal = 0;
for (cnt = 0; cnt < dataSize-1; cnt++) {
if (TheData[cnt] > 208)
TheData[cnt] = 0;
if (TheData[cnt] > 80)
TheData[cnt] = 255;
else
TheData[cnt] = 0;
curChar = TheData[cnt];
if ((curChar == 0) && (state == 0)) {
state = 1;
counter = 0;
}
if ((curChar == 0) && (state == 1)) {
counter++;
}
if ((curChar == 255) && (state == 1) && (counter > 8)) {
state = 2;
}
if ((curChar == 0) && (state == 2)) {
state = 3;
counter = cnt;
}
if ((curChar == 255) && (state == 3)) {
state = 4;
}
if ((curChar == 0) && (state == 4)) {
duration = cnt - counter;
state = 3;
counter = cnt;
if (duration > 35) {
bits[bitCnt] = '1';
outVal = outVal | (1L << bitCnt);
} else
bits[bitCnt] = '0';
bitCnt++;
if (bitCnt > 11) {
state = 5;
return (outVal);
/* printf ("xxx %s xxx\n", bits); */
}
}
if ((curChar == 255) && (state == 5)) {
state = 0;
bits[12] = 0;
bitCnt = 0;
outVal = 0;
}
}
return(0);
}